import { defineConfig, ConfigEnv, loadEnv } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'


// https://vitejs.dev/config/
export default defineConfig(({ mode }: ConfigEnv) => {

  const path = require('path');
  const env = loadEnv(mode, process.cwd(), "");
  console.log(env.ENV_DOMAIN);
  return {
    envPrefix: "ENV_",

    define: {
      __APP_ENV__: env,
    },

    plugins: [uni()],

    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
      },
    },

    build: {
      minify: "terser",
      terserOptions: {
          compress: {
            drop_console: false,
          },
      },
    },

    // 跨域配置
    server: {
      port: 3000,
      proxy: {
          "/api": {
              target: env.ENV_DOMAIN,
              changeOrigin: true,
              rewrite: (path) => path.replace(/^\/api/, "/api"),
          },
      },
    },


  }
});
